<template>

  <div class="mod-config">
    <el-tabs v-model="activeName" @tab-click="changeSort()">
      <el-tab-pane label="全部" name=0 ></el-tab-pane>
      <el-tab-pane label="已通过" name=1 ></el-tab-pane>
      <el-tab-pane label="未通过" name=2 ></el-tab-pane>
    </el-tabs>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">

      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
<!--        <el-button v-if="isAuth('modules:comments:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
        <el-button v-if="isAuth('modules:comments:delete')" type="primary" @click="updateHandle()" :disabled="dataListSelections.length <= 0">批量通过</el-button>
        <el-button v-if="isAuth('modules:comments:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>

      </el-form-item>
    </el-form>
    <el-table

      :row-style="{height:100}"
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="评论id"
        width="70">
      </el-table-column>

      <el-table-column type="expand" label="展开">
        <template slot-scope="scope">
          <el-form label-position="left" inline class="demo-table-expand"  >
            <el-form-item label="课程id:">
              <span style="font-size: 20px" >{{ scope.row.courseId }}</span>
            </el-form-item>
            <el-form-item label="课程类型:">
              <span style="font-size: 20px" v-if="scope.row.courseType==0">视频课</span>
              <span style="font-size: 20px" v-if="scope.row.courseType==1">直播课</span>
            </el-form-item>
            <el-form-item label="评论者ID:">
              <span style="font-size: 20px">{{ scope.row.commentId }}</span>
            </el-form-item>
            <el-form-item label="评论者姓名:">
              <span style="font-size: 20px">{{ scope.row.commentName }}</span>
            </el-form-item>
            <el-form-item label="被回复者ID:">
              <span style="font-size: 20px" v-if="scope.row.replyId!=null">{{ scope.row.replyId }}</span>
            </el-form-item>
            <el-form-item label="被回复者姓名:">
              <span style="font-size: 20px">{{ scope.row.replyName }}</span>
            </el-form-item>
            <el-form-item label="评论时间:">
              <span style="font-size: 20px">{{ scope.row.time }}</span>
            </el-form-item>
            <el-form-item label="根评论的id:">
              <span style="font-size: 20px">{{ scope.row.rootComment }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
<!--     <el-table-column
        prop="courseId"
        header-align="center"
        align="center"
        label="课程的id"
        width="80">
      </el-table-column>-->
<!--      <el-table-column
        prop="courseType"
        header-align="center"
        align="center"
        label="课程的类型"
        width="70"
      >
      </el-table-column>-->
<!--      <el-table-column
        prop="commentId"
        header-align="center"
        align="center"
        label="评论者的id"
        width="70">
      </el-table-column>-->
<!--      <el-table-column
        prop="replyId"
        header-align="center"
        align="center"
        label="被回复者的id，如果没有则为空">
      </el-table-column>-->
<!--     <el-table-column
        prop="commentName"
        header-align="center"
        align="center"
        label="评论者的名字"
        width="150">
      </el-table-column>-->
    <!--   <el-table-column
        prop="replyName"
        header-align="center"
        align="center"
        label="回复者的名字">
      </el-table-column>-->
<!--      <el-table-column
        prop="time"
        header-align="center"
        align="center"
        sortable
        label="评论时间"
      width="120">
      </el-table-column>-->
      <el-table-column
        header-align="center"

        label="评论">
        <template slot-scope="scope">
          <div class="comment" style="height: 220px;overflow: auto">
            <ul  class="comment-list">
              <li
                class="comment-item"
              >
                <div class="comment-content-wrapper">
                  <p>
                    <span class="name">{{ scope.row.commentName }}</span>
                  </p>
                  <p class="content">
                    {{ scope.row.content }}
                  </p>
                  <p>
                    <span class="time">时间：{{ scope.row.time }}</span>
                  </p>
                </div>
              </li>
            </ul>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="isPublic"
        header-align="center"
        align="center"
        width="80"
        label="审核状态">
        <template slot-scope="scope">
          <div v-if="scope.row.isPublic === 0"><el-tag type="warning" effect="light">未通过</el-tag></div>
          <div v-if="scope.row.isPublic === 1"><el-tag type="success" effect="dark">已通过</el-tag></div>
        </template>
      </el-table-column>


<!--      <el-table-column
        prop="showStatus"
        header-align="center"
        align="center"
        label="逻辑删除位">
      </el-table-column>-->

   <!--   <el-table-column
        prop="rootComment"
        header-align="center"
        align="center"
        label="根评论的id">
      </el-table-column>-->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
<!--          <el-button type="text" size="big" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>-->
          <el-button type="success" size="small" @click="updateHandle(scope.row.id)" v-if="scope.row.isPublic==0">通过</el-button>

          <el-button type="danger" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>

<!--    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
    <div style="margin: 15px 0;"></div>
    <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
      <el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox>
    </el-checkbox-group>
    <div class="comment">
      <ul v-if="dataList.length" class="comment-list">
        <li
          v-for="(comment,index) in dataList"
          :key="index"
          class="comment-item"
        >

          <div class="comment-content-wrapper">
            <p>
              <span class="name">{{ comment.commentName }}</span>
            </p>
            <p class="content">
              {{ comment.content }}
            </p>
            <p>
              <span class="time">时间：{{ comment.time }}</span>
            </p>
          </div>
        </li>
      </ul>
    </div>-->

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './comments-add-or-update'

  export default {

    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,

        activeName: 0
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {

        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/course/comments/list'),
          method: 'get',
          params: this.$http.adornParams({
            'sort':this.activeName,
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {

            this.dataList = data.page.list
            this.totalPage = data.page.totalCount

          } else {
            this.dataList = []
            this.totalPage = 0

          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/course/comments/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      //审核通过
      updateHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '通过' : '批量通过'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/course/comments/pass'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      changeSort(){
        this.dataForm.key=''
        this.getDataList()
      },



    }
  }
</script>


<style lang="stylus" scoped>
.demo-table-expand
  font-size: 0;

.demo-table-expand label
  width: 90px;
  color: #99a9bf;

.demo-table-expand
  .el-form-item
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;


.comment
  .score-overview
    padding: 24px 32px;
    display: flex;
    align-items: center;
    background-color: #fff;
    box-shadow: 0 0 8px 4px rgba(7,17,27,0.1);
    border-radius: 12px;
    .star-box
      flex: 1;
      & > span
        display: inline-block;
        vertical-align:  middle;
        line-height: 24px;
        &.title
          width: 40px;
          text-align: center;
          color: #1c1f21;
          font-size: 14px;
          line-height: 16px;
          font-weight: 700;
        &.score
          padding-left: 5px;
          font-size: 32px;
          color: #4d555d;
          font-weight: 700;
      >>> .star
        margin-left: 10px;
        vertical-align: middle;
        .star-item
          margin-right: 3px;
    .score-box
      margin-left: 50px;
      & > span
        display: inline-block;
        vertical-align:  middle;
        line-height: 24px;
        font-size: 14px;
        &.score
          padding-left: 12px;
          font-size: 26px;
          color: #f90;
          font-weight: 700;
  .comment-list
    margin-top: 24px;
    .comment-item
      margin-bottom: 8px;
      padding: 24px; 36px;
      display: flex;
      align-items: flex-start;
      background-color: #fff;
      box-shadow: 0 0 8px 4px rgba(7,17,27,.1);
      border-radius: 12px;
      .img-box
        margin-right: 20px;
        flex: 0 0 48px;
        width: 48px;
        height: 48px;
        & > img
          display: block;
          width: 100%;
          height: 100%;
          border-radius: 50%;
          background-color: #eee;
      .comment-content-wrapper
        flex: 1;
        & > p
          font-size: 14px;
          color: #14191e;
          line-height: 24px;
          &.content
            margin-top: 4px;
            margin-bottom: 8px;
            line-height: 28px;
          .name
            color: #787d82;
            font-weight: 700;
          .score, .time
            float: right;
          .time
            color: #b5b9bc;
            font-size: 12px;
</style>
